import bootstrap
bootstrap.bootstrap(__file__)
from csv import reader
from pyceab.schedule.models import Offering, TimeSlot
from pyceab.course.models import Course


HEADERS = (
        'department',
        'course_code',
        'credit',
        'full_name',
        'type',
        'section',
        'day',
        'start_time',
        'end_time',
        'term',
        )

def load_data_from_file(path):
    csv_reader = reader(open(path, 'r'))
    for row in csv_reader:
        timeslot = dict(zip(HEADERS, row))
        try:
            c = Course.objects.get(department=timeslot['department'], course_code=timeslot['course_code'])
            o,status = Offering.objects.get_or_create(course=c, type=timeslot['type'], section=timeslot['section'], term=timeslot['term'])

            print timeslot
            t,status = TimeSlot.objects.get_or_create(offering=o, day=timeslot['day'], start_time=timeslot['start_time'], end_time=timeslot['end_time'])

        except Course.DoesNotExist:
            # course doesn't exist
            pass
            

load_data_from_file('/home/benjamin/School/Software/sd322-w09/pyceab/syde_schedule.csv')
